package ma.techit.pfe.agence.voyage.controller;

import java.io.IOException;
import java.util.List;

import ma.techit.pfe.agence.voyage.bo.interfaces.ServiceHotelBoIn;
import ma.techit.pfe.agence.voyage.model.ServiceHotel;
import ma.techit.pfe.agence.voyage.util.JsonJtableServiceHotelListResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


@Controller
public class ManageServiceHotelController {
	
	 @Autowired
	 private ServiceHotelBoIn serviceHotelBo;
	
	 /* Table data load - This loads the data for the table */
		@RequestMapping(value = "/serviceVol/getAllServiceHotel", method = RequestMethod.POST)
		@ResponseBody JsonJtableServiceHotelListResponse getAllServicesHotel(
				@RequestParam int jtStartIndex, @RequestParam int jtPageSize)
						throws IOException {
				
					JsonJtableServiceHotelListResponse jstr;
					List<ServiceHotel> serviceList;

					 System.out.println("printing service hotel retuns no failure");   
					try {
						System.out.println("hello error");

						int serviceHotelCount = serviceHotelBo.countAllService();

						System.out.println("serviceVolCount ====>" + serviceHotelCount);
						System.out.println("start index ===> " + jtStartIndex
								+ " page size ===>" + jtPageSize);

						serviceList = serviceHotelBo.find(jtStartIndex, jtPageSize);

//						System.out.println("hello error  " + serviceList.get(0));  

						jstr = new JsonJtableServiceHotelListResponse("OK", serviceList, serviceHotelCount);

						System.out.println("jstr.getMessage()--------------->"
								+ jstr.getMessage());
						System.out.println("jstr.getRecords()--------------->"
								+ jstr.getRecords());

					} catch (Exception e) {
						// TODO: handle exception
						System.out.println("in the catch clause");
						jstr = new JsonJtableServiceHotelListResponse("ERROR", e.getMessage());
					}
					return jstr;
				}

}
